<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
    <head>
        <title>美业红</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1">
        <link href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
        <link href="/public/css/main.css" rel="stylesheet">
        <script type='text/javascript' src='/public/js/jquery-3.1.1.min.js'></script>
        <script type="text/javascript" src='/public/js/jquery.validate.js'></script>
        <script type="text/javascript" src='/public/js/main/main.js'></script>
        <script>
            var _hmt = _hmt || [];
            (function () {
                var hm = document.createElement("script");
                hm.src = "//hm.baidu.com/hm.js?8d43b5b5d798921b66d689f7a792e6e2";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();
        </script>
        <script type="text/javascript">
            document.domain = '<?php echo _DOMAIN_ALL_;?>';
        </script>
        <link rel="shortcut icon" type="image/ico" href="/favicon.ico">
    </head>
    <body style="background-color: #f4f4f4;">
        <div class="navigation">
            <div class='navlogo'>
            <a href='/'><img class='_navlogo' src="/public/images/logo.png"></a>
            </div>
            <div class='navson'>
                <ul class='fr'>
                <li><a href='/' class='anchor'><b>主页</b></a></li>
                <li><a href="/home/store" class='anchor'><b>店铺</b></a></li>
                <li><a href="/home/barber" class='anchor'><b>成员</b></a></li>
                <li><a href="/home/action" class='anchor'><b>活动</b></a></li>
                <li><a href="/home/order" class='anchor'><b>订单</b></a></li>
                <li><a href="/home/coupon" class='anchor'><b>优惠券</b></a></li>
                <li><a href="/home/goods" class='anchor'><b>商品</b></a></li>
                </ul>
           </div>
            <?php if($_SESSION['id']>0){?>
            <div style="float:right;padding-right:10%">你好:<span id='login_name'></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='anchor' href='/home/passport/repassword'>修改密码</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='anchor' href='/home/passport/logout'>退出</a></div>
            <?php }?>
        </div>
        <div style='margin-top:80px;width:100%'>
            <img class='_navlogo' src="/public/images/contentlogo.png" style='width:100%;height:100px'>
        </div>
        <div class='container'>
            <div class='_main'>
            <div class='_line'></div> 
<div class="_contro">
    <a href="/home/goods/" class="_a"><font style='font-size:1.5rem'>返回列表页</font></a>
</div>
<div class='_cut'></div>
<div class='content'>
<form action='/home/goods/submit' method='post'  id='form'>
    <div>
        <div class="form-group row">
            <label for="exampleInputName2" class="_label" >店铺:</label>
            <select id="store_id" name="store_id">
                <option value='0'>全部</option>
                <?php foreach($_store as $v){?>
                <option value='<?php echo $v['id'];?>' <?php if($item['store_id']==$v['id']){echo "selected='selected'";}?>><?php echo $v['name'];?></option>
                <?php }?>
            </select>
        </div>
    </div>
    <div>
        <div class="form-group row">
            <label for="exampleInputName2" class="_label" >商品名称:</label>
            <input type="text" class="row _minput" name='name' placeholder="" value="<?php echo $item['name'];?>"/>
        </div>
    </div>
    <div>
        <div class="form-group row">
            <label for="exampleInputName2" class="_label" >商品小标题:</label>
            <input type="text" class="row _minput" name='title' placeholder="" value="<?php echo $item['title'];?>"/>
        </div>
    </div>
    <div>
        <div class="form-group row">
            <label for="exampleInputName2" class="_label" >商品种类:</label>
            <select id="type" name="type" class="_select valid">
                <option value='0' <?php if($item['type'] == 0){echo 'selected="selected"';}?> >剪发类</option>
                <option value='1' <?php if($item['type'] == 1){echo 'selected="selected"';}?> >烫染类</option>
                <option value='2' <?php if($item['type'] == 2){echo 'selected="selected"';}?> >护理类</option>
                <option value='3' <?php if($item['type'] == 3){echo 'selected="selected"';}?> >仪器类</option>
                <option value='4' <?php if($item['type'] == 4){echo 'selected="selected"';}?> >人工类</option>
            </select>
        </div>
    </div>
    <div>
        <div class="form-group row">
            <label for="exampleInputName2" class="_label" >商品类型:</label>
            <select id="type_meal" name="is_meal_set" class="_select valid">
                <option value='0' <?php if($item['is_meal_set'] == 0){echo 'selected="selected"';}?> >单品</option>
                <option value='1' <?php if($item['is_meal_set'] == 1){echo 'selected="selected"';}?> >套餐</option>
            </select>
        </div>
    </div>
    <!--下面的div 当是套餐是显示-->
    <div id='meal' style='display:none' >
        <div>
            <div class="form-group row">
                <label for="exampleInputName2" class="_label" >商品:</label>
                <select id="meal_set2" name="meal_set[]" class="_select valid">

                </select>
                &nbsp;&nbsp;&nbsp;&nbsp;
                数量：<input type="text" name="num[]"  id='num2' style="width:5rem;">
            </div>
        </div>
        <div>
            <div class="form-group row">
                <label for="exampleInputName2" class="_label" >&nbsp;&nbsp;&nbsp;&nbsp;</label>
                <select id="meal_set1" name="meal_set[]"  class="_select valid">

                </select>
                &nbsp;&nbsp;&nbsp;&nbsp;
                数量：<input type="text" name="num[]" id='num1' style="width:5rem;">
            </div>
        </div>
        <div>
            <div class="form-group row">
                <label for="exampleInputName2" class="_label" >&nbsp;&nbsp;&nbsp;&nbsp;</label>
                <select id="meal_set0" name="meal_set[]" class="_select valid">

                </select>
                &nbsp;&nbsp;&nbsp;&nbsp;
                数量：<input type="text" name="num[]" id='num0' style="width:5rem;">
            </div>
        </div> 
    </div>
    <div>
        <div class="form-group row">
            <label for="exampleInputName2" class="_label" >商品价格:</label>
            <input type="text"  name='price' placeholder="" value="<?php echo ($item['price']/100);?>" style='width:5%' >&nbsp;元
        </div>
    </div>
    <div>
        <div class="form-group row">
            <label for="exampleInputName2" class="_label" >商品成员:</label>
            <?php $members = json_decode($item['level']); if($members){ ?>
            <input name="member" type="radio" value="0"  <?php if(in_array(0,$members)){ echo 'checked ';} ?> >全部成员&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            <input name="member" type="radio" value="1"  <?php if(!in_array(0,$members)){ echo 'checked ';} ?> />指定成员
            <?php }else{?>
            <input name="member" type="radio" value="0"  checked >全部成员&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            <input name="member" type="radio" value="1"   />指定成员
            <?php } ?>
        </div>
        <div id='members' style='display:none' >
            <label for="exampleInputName2" class="_label" ></label>
            <label><input name="members[]" type="checkbox" value="6" <?php if(in_array(6,$members)){ echo 'checked="checked" ';} ?> />&nbsp;高级助理 </label>&nbsp;&nbsp;
            <label><input name="members[]" type="checkbox" value="1" <?php if(in_array(1,$members)){ echo 'checked="checked" ';} ?> />&nbsp;高级发型师 </label>&nbsp;&nbsp;
            <label><input name="members[]" type="checkbox" value="2" <?php if(in_array(2,$members)){ echo 'checked="checked" ';} ?> />&nbsp;高级总监 </label>&nbsp;&nbsp;
            <div>
            <label for="exampleInputName2" class="_label" ></label>
            <label><input name="members[]" type="checkbox" value="3" <?php if(in_array(3,$members)){ echo 'checked="checked" ';} ?> />&nbsp;高级顾问 </label>&nbsp;&nbsp;
            <label><input name="members[]" type="checkbox" value="4" <?php if(in_array(4,$members)){ echo 'checked="checked" ';} ?> />&nbsp;高级美容师 </label>&nbsp;&nbsp;
            <label><input name="members[]" type="checkbox" value="5" <?php if(in_array(5,$members)){ echo 'checked="checked" ';} ?> />&nbsp;高级经理 </label>&nbsp;&nbsp;
            </div>
        </div>
    </div>
    <div>
        <div   >
        <div class='form-group row'  >
                <label style='float:left' for="exampleInputName2" class="_label">商品图:</label>
                 <div style='padding-bottom:2rem'> 
                    <input type='button' value='添加' id='add'  >
                    <span class="_prompt">宣传用图片建议长宽比例1:1；2M以内，支持“jpg,jpeg,png”</span>
                </div>
                <label style='float:left;' for="exampleInputName2" class="_label"></label>
                <span id='ad' style='float:left;'>
                <?php if($item['id']>0){ $h = count($item['images']); ?>
                <?php foreach($item['images'] as $k=>$v){ ?>
                <span id='asd' style='float:left;margin-top:1rem;' >
                    
                <img src="<?php echo "http://".IMAGE_DOMAIN.$item['images'][$k]['image']; ?>" style="width:15rem;height: 15rem;border:1px;border-color: black" id="s<?php echo $k;?>_img"  alt='商品图1'/>
                <?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/goods/create')){ ?>
                <a href='javascript:;'; onclick='error_(this)'; ><img src='/public/images/error1.png' width='20px' style='margin-top:-15rem;margin-left:-1rem;' ></a>
                <?php } ?>
                <input type='hidden' name='image[]' value="<?php echo $item['images'][$k]['image'];?>" id='s<?php echo $k;?>'>
                <div style='margin-left:-1rem;' >
                    <iframe id='imgs' src="http://<?php  echo IMAGE_DOMAIN;?>/index.php?id=s<?php echo $k;?>&type=2" frameborder="no" border="0" scrolling='no' style="width:20rem;height: 4rem;padding-top: 1rem" ></iframe>
                </div>
                </span>
                <?php } ?>
                <?php }else{?>
                <span id='asd' style='float:left;margin-top:1rem;' >
                <img src="<?php echo "http://".IMAGE_DOMAIN.'/upload/product.png'; ?>" style="width:15rem;height:15rem;border:1px;border-color: black" id="s0_img"  alt='商品图'/>
                <input type='hidden' name='image[]' value="<?php echo '/upload/product.png'; ?>" id='s0'>
                <div >
                    <iframe id='imgs' src="http://<?php  echo IMAGE_DOMAIN;?>/index.php?id=s0&type=2" frameborder="no" border="0" scrolling='no' style="width:20rem;height: 4rem;padding-top: 1rem" ></iframe>
                </div>
                <?php }?> 
                
                </span>
                </span>
               
        </div>
        </div>
    </div>
        <div class='form-group row'>
            <div><label for="exampleInputName2" class="_label">商品介绍:</label></div>
                <label for="exampleInputName2" class="_label"></label>
                <textarea name='intro' id="_intro" class="_textarea" style="width:40%"><?php echo $item['intro']; ?></textarea>
        </div>
        <div class="form-group _submit_div row">
                <input name='id' type='hidden' value="<?php if($copy==false){echo $item['id'];}?>"/>
                <input name='item_number' type='hidden' value="<?php if($copy==false){echo $item['item_number'];}?>"/>
                <input name='create' id='create' class='_button' type="button" value="预览" onclick="_submit(2);"/>
                <input name='caogao' id='caogao' class='_button' type="submit" value="保存草稿" onsubmit="return _submit(1);"/>
        </div>
</form>

</div>
<script type="text/javascript">
    
    $(document).ready(function () {
        $("#type_meal").change(function () {
            type = $('#type_meal').val();
            if(type==1){
                $('#meal').show();
            }
            if(type==0){
                $('#meal').hide();
            }   
        });
        var n = Number($('#ad').children().length)+Number(1);
        $('#add').click(function(){
            if($('#ad').children().length==4){
                alert('最多添加4张图片！');
                return;
            }

            var html='';
            html += "<span style='float:left;margin-top:1rem;' id='as";
            html += n;
            html += "'; ><img src='<?php echo 'http://'.IMAGE_DOMAIN.'/upload/product.png'; ?>' style='width:15rem;height:15rem;border:1px;border-color: black' id='s";
            html += n;
            html +="_img'  alt='商品图'/><a href='javascript:;'; onclick='error(";
            html += n;
            html += ")'; ><img src='/public/images/error1.png' width='20px' style='margin-top:-15rem;' ></a>";
            html +="<input type='hidden' name='image[]' value='<?php echo '/upload/product.png'; ?>' id='s";
            html += n;
            html +="'><div ><iframe id='imgs' src='http://<?php  echo IMAGE_DOMAIN;?>/index.php?id=s";
            html += n;
            html +="&type=2' frameborder='no' border='0' scrolling='no' style='width:20rem;height: 4rem;padding-top: 1rem' ></iframe></div></span>";
            $('#ad').append(html);
            n = n+1;
        });
       
        $('input:radio[name="member"]').change(function (){
            m = $('input:radio[name="member"]:checked').val();
            if(m==1){
                $('#members').show();
            }
            if(m==0){
                $('#members').hide();
            }
        });
        $("#store_id").change(function(){
                            store_id = $("#store_id").val();
                            $.ajax({
                                url: "/home/goods/item?store_id="+store_id,
                                async: true,
                                success: function (data) {
                                    if(data=='false'){
                                        return;
                                    }
                                    data = eval('(' + data + ')');
                                    var str = "<option value='0'>请选择套餐种类</option>";
                                    $.each(data, function (i, v) {
                                        str += "<option value='"+v.id+"'>"+v.name+"</option>"
                                    });
                                    $('#meal_set2').html(str);
                                    $('#meal_set1').html(str);
                                    $('#meal_set0').html(str);
                                }
                            });
        });
        if($('#type_meal').val()==1){   
            $('#meal').show();
            store_id = $("#store_id").val();
            item_number = "<?php echo $item['item_number'] ?>";
            var id = "<?php echo $item['id'] ?>";
            $.ajax({
                url:"/home/goods/getMealSetByMember?store_id="+store_id+"&item_number="+item_number+"&id="+id,
                async: true,
                success: function (data) {
                    if(data=='false'){
                        return;
                    }
                    data = eval('(' + data + ')');
                        $.each(data, function (i, v) {
                            if(v.name){
                                var str = "<option value='"+v.id+"' checked >"+v.name+"</option>";
                                $('#num'+(2-i)).val(v.number);
                                $('#meal_set'+(2-i)).html(str);
                            }
                                $.ajax({
                                    url: "/home/goods/item?store_id="+store_id,
                                    async: true,
                                    success: function (data) {
                                        if(data=='false'){
                                            return;
                                        }
                                        data = eval('(' + data + ')');
                                        str += "<option value='0'>请选择套餐种类</option>";
                                        $.each(data, function (i, v) {
                                            str += "<option value='"+v.id+"'>"+v.name+"</option>"
                                        });
                                        $('#meal_set'+(2-i)).html(str);
                                        str = '';
                                    }
                                });
                        });
                    if(data.length<3){
                        var len = data.length;
                        $.ajax({
                                url: "/home/goods/item?store_id="+store_id,
                                async: true,
                                success: function (data) {
                                    if(data=='false'){
                                        return;
                                    }
                                    data = eval('(' + data + ')');
                                    var str = "<option value='0'>请选择套餐种类</option>";
                                    $.each(data, function (i, v) {
                                        str += "<option value='"+v.id+"'>"+v.name+"</option>"
                                    });
                                    if(len==2){
                                        $('#meal_set0').html(str);
                                    }
                                    if(len==1){
                                        $('#meal_set0').html(str);
                                        $('#meal_set1').html(str);
                                    }if(len==0){
                                        $('#meal_set2').html(str);
                                        $('#meal_set1').html(str);
                                        $('#meal_set0').html(str);
                                    }
                                    
                                }
                        });
                    }
                }
            });
        }
        if($('input:radio[name="member"]:checked').val()==1){
            $('#members').show();
        }

        $("#form").validate({
                            rules: {
                                store_id: {
                                    required: true,
                                    min: 1,
                                },
                                name: {
                                    required: true,
                                },
                                title: {
                                    required: true,
                                },
                                type: {
                                    required: true,
                                },
                                is_meal_set: {
                                    required: true,
                                },
                                price: {
                                    required: true,
                                    number:true,
                                }

                            },
                            messages: {
                                store_id: {
                                    required: "请选择店铺",
                                    min: "请选择店铺",
                                },
                                name: {
                                    required: '请输入商品名称',
                                },
                                title: {
                                    required: '请输入商品副标题',
                                },
                                type: {
                                    required: '请商品种类',
                                },
                                is_meal_set: {
                                    required: '请商品类型',
                                },
                                price: {
                                    required: '请填写价格',
                                    number:'请填写数字',
                                }

                            
                            }
                        });

    });
    
    function error(n){
        $('#as'+n).remove();
    }
    function error_(obj){
        $(obj).parent().remove();

    }
   
    function _submit(type) {
        if (type == 1) {
            $('#create').remove();
        } else {
            $('#caogao').remove();
        }
        if($('input:hidden[name="image[]"]').val()== undefined){
            alert('请至少上传一张商品图！');
            return;
        }
        var content = $("#_intro").val();
        content = content.replace(/<br\/>/,"\n");
        content = content.replace(/<span style=\'color:red\'>/,"");
        content = content.replace(/<\/span>/,"");
        content = content.replace(/\n/g, "<br/>");
        content = content.replace(/[\d]{1,}/g, "<span style='color:red'>$&</span>");
        $("#_intro").val(content);
        var ty = check();
        if(ty==false){
            return;
        }
        $('#form').submit();
    }
    function check(){
        if($('#type_meal').val()==1){
            if($('#meal_set2').val()<1){
                alert('请选择套餐商品');
                return false;
            }
            if($('input:text[name="num[]"]').val()==''){
                alert('请填写商品数量');
                return false;
            }
        }
    }


</script>
</div>
</div>
<div class='_line'></div>
<div class="newfooter">
    ©2015-2017 All Rights Reserved ( 京ICP备15010043号 ) 
</div>
<div id='mask_layer' style="text-align: center;width:100%;height:100%;overflow:hidden;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#8E8E8E',endColorstr='##8E8E8E');
     background-color:rgba(255, 255, 255, 0.4);position:fixed; _position:absolute; top:0;left:0; z-index:5000;display:none ">
    <div style="padding-top: 20%"><h1><b>loading<span id="_loading"></span></b></h1></div>
</div>
</body>
<script type="text/javascript" src='/public/js/top.js'></script>
</html>